#!/bin/bash

if [ $(id -u) != "0" ]; then
    printf "Error: You must be root to run this tool!\n"
    exit 1
fi
clear
printf "
#####################################################
#                                                   #
# This is a Shell-Based tool of redis installation  #
# Version: 1.0                                      #
# Author: Sean Yu                                   #
# For debian 32bit and 64bit                        #
#                                                   #
#####################################################
"

apt-get -y update
apt-get -y upgrade
apt-get -y install g++ automake libtool make

rm -fr /tmp/libunwind
rm -fr /tmp/gperftools
rm -fr /tmp/redis

mkdir /tmp/libunwind
cd /tmp/libunwind
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar zxvf libunwind-1.1.tar.gz
cd libunwind-1.1
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install


mkdir /tmp/gperftools
cd /tmp/gperftools
wget http://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
tar zxvf gperftools-2.1.tar.gz
cd gperftools-2.1
./configure --enable-minimal--disable-cpu-profiler--disable-heap-profiler --disable-heap-checker--disable-debugalloc
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig

mkdir /tmp/redis
cd /tmp/redis
wget http://download.redis.io/releases/redis-2.6.16.tar.gz
tar zxvf redis-2.6.16.tar.gz
cd redis-2.6.16
make USE_TCMALLOC=yes FORCE_LIBC_MALLOC=yes
make install

rm -rf /etc/init.d/redis-server
wget https://linud-shell-script.googlecode.com/git/redis/redis-server

rm -rf /etc/redis.conf
wget https://linud-shell-script.googlecode.com/git/redis/redis.conf

mv redis-server /etc/init.d/redis-server
chmod +x /etc/init.d/redis-server
mv redis.conf /etc/redis.conf

useradd redis
mkdir -p /var/lib/redis 
mkdir -p /var/log/redis 
chown redis.redis /var/lib/redis 
chown redis.redis /var/log/redis
update-rc.d redis-server defaults
/etc/init.d/redis-server start

clear
printf "
#####################################################
#                                                   #
# This is a Shell-Based tool of redis installation  #
# Version: 1.0                                      #
# Author: Sean Yu                                   #
# For debian 32bit and 64bit                        #
#                                                   #
#####################################################
"
echo "redis start "
ps aux | grep redis


